package com.vpen.order.controller;

import com.vpen.commons.pojo.CommonResult;
import com.vpen.commons.pojo.Payment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


/**
 * @Version 1.0
 * @Author: Vpen
 * @Date: 2021/3/16 20:43
 * @Content:
 */
@RestController
public class OrderController {
    /**
     * @author:韦鹏
     * @desc: cloud-payment-service是服务提供者注册的应用名称
     * */
    private static final String PAYMENT_URL = "http://cloud-payment-service";

    @Resource(name = "restTemplate")
    private RestTemplate restTemplate;

    @RequestMapping(value = "/order/payment/insert", method = RequestMethod.POST)
    public CommonResult<Payment> creat(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/insert", payment, CommonResult.class);

    }

    @GetMapping(value = "/order/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);
    }

    @GetMapping("/order")
    public CommonResult getTest(){
        return new CommonResult(200,"成功");
    }
}
